use std::fmt::{Display, Formatter};
use std::path::Path;
use clap::Parser;
use super::check_input_file_path;

#[derive(Debug, Parser)]
pub struct CsvOpts {
    #[arg(short, long, value_parser = check_input_file_path)]
    pub input: String,

    #[arg(short, long)]
    pub output: Option<String>,

    #[arg(short, long, default_value = "json", value_parser = parse_format)]
    pub format: OutputFormat,

    #[arg(short, long, default_value = ",")]
    pub delimiter: char,

    #[arg(long, default_value_t = false)]
    pub header: bool,

}





#[derive(Debug, Copy, Clone)]
pub enum OutputFormat {
    Json,
    Yml,

}

impl Display for OutputFormat {
    fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
        match self {
            OutputFormat::Json => write!(f, "json"),
            OutputFormat::Yml => write!(f, "yml"),
        }
    }
}


pub fn parse_format(format: &str) -> anyhow::Result<OutputFormat, String> {
    match format.to_lowercase().as_str() {
        "json" => Ok(OutputFormat::Json),
        "yml" => Ok(OutputFormat::Yml),
        _ => Err("Invalid format".to_string()),
    }
}